//
//  NetworkTools.h
//  RZIM
//
//  Created by reyzhang on 2021/7/26.
//

#import <Foundation/Foundation.h>
#import "RZIMDefine.h"

NS_ASSUME_NONNULL_BEGIN
//请求超时
#define TIMEOUT 5.0f

typedef NS_ENUM(NSInteger,NetworkHTTPMethod) {
    HTTPMethodGET,
    HTTPMethodPOST,
};

@interface NetworkTools : NSObject


typedef void(^RZSuccessBlock)(NSDictionary * dic);
typedef void(^RZFailureBlock)(NSError * error);
typedef void(^RZProgressBlock)(NSProgress *progress);

//key value 的形式
+ (void)get:(NSString *)url
 parameters:(NSDictionary *)parameters
     succes:(RZSuccessBlock)success
    failure:(RZFailureBlock)failure;

+ (void)post:(NSString *)url
  parameters:(NSDictionary *)parameters
      succes:(RZSuccessBlock)success
     failure:(RZFailureBlock)failure;


// json串中有body的形式
+ (void)getjson:(NSString *)url
    parameters:(NSDictionary *)parameters
    succes:(RZSuccessBlock)success
    failure:(RZFailureBlock)failure;


+ (void)postjson:(NSString *)url
      parameters:(NSDictionary *)parameters
          succes:(RZSuccessBlock)success
         failure:(RZFailureBlock)failure;



/**
 下载文件，并保存到本地。
 Block返回本地文件地址
 */
+ (void)downloadFileWithUrl:(NSURL *)remoteUrl
            completeHandler:(void(^)(NSURL *localUrl))block;



/**
 判断文件是否存在 且如果存在 是否允许删除
 */
+ (BOOL)isFileExist:(NSString *)fileName needDel:(BOOL)needDel;


+ (BOOL)isFileExist:(NSString *)fileName;



/**
 流上传（文件流，图片流）
 */
+ (void)uploadWithURL:(NSString *)URL
               files:(NSArray *)files
             progress:(RZProgressBlock)progress
              success:(RZSuccessBlock)success
              failure:(RZFailureBlock)failure;


@end

NS_ASSUME_NONNULL_END
